home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / muds / pennmush.000 / pennmush-1.50-p8-linux.tar / pennmush / log.c < prev    next >
C/C++ Source or Header  |  1993-04-21  |  4KB  |  180 lines

  1. /* log.c */
  2.  
  3. #include <stdio.h>
  4. #include <varargs.h>
  5. #include <sys/time.h>
  6.  
  7. #include "config.h"
  8. #include "externs.h"
  9. #include "interface.h"
  10.  
  11. #ifdef LOG_WIPES_OKAY
  12. #include <pwd.h>
  13. #endif
  14.  
  15. char *quick_unparse(object)
  16.      dbref object;
  17. {
  18.   static char buff[BUFFER_LEN];
  19.  
  20.   switch (object) {
  21.   case NOTHING:
  22.     sprintf(buff, "*NOTHING*");
  23.     break;
  24.   case HOME:
  25.     sprintf(buff, "*HOME*");
  26.     break;
  27.   default:
  28.     sprintf(buff, "%s(#%d%s)", 
  29.         Name(object), object, unparse_flags(object, GOD));
  30.   }
  31.  
  32.   return buff;
  33. }
  34.  
  35. void start_log(fp, filename)
  36.      FILE **fp;
  37.      const char *filename;
  38. {
  39.   *fp = fopen(filename, "w");
  40.   if (*fp == NULL) {
  41.     fprintf(stderr, "WARNING: cannot open log %s\n", filename);
  42.     *fp = stderr;
  43.   }
  44. }
  45.  
  46. void end_log(fp)
  47.      FILE *fp;
  48. {
  49.   if (fp != stderr) {
  50.     fprintf(fp, "END OF LOG.\n");
  51.     fflush(fp);
  52.     fclose(fp);
  53.   }
  54. }
  55.  
  56. void do_log(logtype, player, object, va_alist)
  57.      int logtype;
  58.      dbref player;
  59.      dbref object;
  60.      va_dcl
  61. {
  62.   /* take a log type and format list and args, write to appropriate logfile.
  63.    * log types are defined in db.h
  64.    */
  65.  
  66.   time_t tt;
  67.   struct tm *ttm;
  68.   char timebuf[16];
  69.   char tbuf1[BUFFER_LEN];
  70.   va_list args;
  71.   char *fmt;
  72.   char unp1[BUFFER_LEN], unp2[BUFFER_LEN];
  73.  
  74.   va_start(args);
  75.   fmt = va_arg(args, char *);
  76.   (void) vsprintf(tbuf1, fmt, args);
  77.   va_end(args);
  78.  
  79.   time(&tt);
  80.   ttm = localtime(&tt);
  81.   sprintf(timebuf, "%d%d/%d%d %d%d:%d%d:%d%d", 
  82.       (((ttm->tm_mon) + 1) / 10), (((ttm->tm_mon) + 1) % 10),
  83.       (ttm->tm_mday / 10), (ttm->tm_mday % 10),
  84.       (ttm->tm_hour / 10), (ttm->tm_hour % 10),
  85.       (ttm->tm_min / 10), (ttm->tm_min % 10),
  86.       (ttm->tm_sec / 10), (ttm->tm_sec %10));
  87.  
  88.   switch (logtype) {
  89.   case LT_ERR:
  90.     fprintf(stderr, "%s  ERR: %s\n", timebuf, tbuf1);
  91.     fflush(stderr);
  92.     break;
  93.   case LT_CMD:
  94.     if (options.log_commands) {
  95.       strcpy(unp1, quick_unparse(player));
  96.       strcpy(unp2, quick_unparse(getloc(player)));
  97.       if (Suspect(player))
  98.     fprintf(cmdlog_fp, "%s  CMD: SUSPECT %s in %s: %s\n", 
  99.         timebuf, unp1, unp2, tbuf1);
  100.       else
  101.     fprintf(cmdlog_fp, "%s  CMD: %s in %s: %s\n",
  102.         timebuf, unp1, unp2, tbuf1);
  103.     } else {
  104.       if (Suspect(player)) {
  105.     strcpy(unp1, quick_unparse(player));
  106.     strcpy(unp2, quick_unparse(getloc(player)));
  107.     fprintf(cmdlog_fp, "%s  CMD: SUSPECT %s in %s: %s\n", 
  108.         timebuf, unp1, unp2, tbuf1);
  109.       }
  110.     }
  111.     fflush(cmdlog_fp);
  112.     break;
  113.   case LT_WIZ:
  114.     strcpy(unp1, quick_unparse(player));
  115.     if (GoodObject(object)) {
  116.       strcpy(unp2, quick_unparse(object));
  117.       fprintf(wizlog_fp, "%s  WIZ: %s --> %s: %s\n",
  118.           timebuf, unp1, unp2, tbuf1);
  119.     } else {
  120.       fprintf(wizlog_fp, "%s  WIZ: %s: %s\n", timebuf, unp1, tbuf1);
  121.     }
  122.     fflush(wizlog_fp);
  123.     break;
  124.   case LT_CONN:
  125.     fprintf(connlog_fp, "%s  NET: %s\n", timebuf, tbuf1);
  126.     fflush(connlog_fp);
  127.     break;
  128.   case LT_TRACE:
  129.     break;
  130.   case LT_RPAGE:
  131.     break;
  132.   case LT_CHECK:
  133.     break;
  134.   case LT_HUH:
  135.     if (!controls(player, getloc(player))) {
  136.       strcpy(unp1, quick_unparse(player));
  137.       strcpy(unp2, quick_unparse(getloc(player)));
  138.       fprintf(cmdlog_fp, "%s  HUH: %s in %s [%s]: %s\n",
  139.           timebuf, unp1, unp2, Name(Owner(getloc(player))), tbuf1);
  140.       fflush(cmdlog_fp);
  141.     }
  142.     break;
  143.   default:
  144.     fprintf(stderr, "%s  ERR: %s", timebuf, tbuf1);
  145.     fflush(stderr);
  146.   }
  147. }
  148.  
  149. #ifdef LOG_WIPES_OKAY
  150. void do_logwipe(player, log_name, str)
  151.      dbref player;
  152.      char *log_name;
  153.      char *str;
  154. {
  155.     /* Wipe out a game log. This is intended for those emergencies where
  156.      * the log has grown out of bounds, overflowing the disk quota, etc.
  157.      * Because someone with the god password can use this command to wipe
  158.      * out 'intrusion' traces, we also require the password of the account
  159.      * the game is running on to be given.
  160.      */
  161.  
  162.     struct passwd *entry;
  163.     char salt[2];
  164.  
  165.     if (!God(player)) {
  166.     notify(player, "Permission denied.");
  167.     return;
  168.     }
  169.  
  170.     entry = getpwuid(getuid());
  171.     strncpy(salt, entry->pw_passwd, 2);
  172.  
  173.     if (strcmp(crypt(salt, str), entry->pw_passwd) != 0) {
  174.     do_log(LT_WIZ, player, NOTHING, 
  175.            "Invalid attempt to wipe log %s, password %s");
  176.     return;
  177.     }
  178. }
  179. #endif                /* LOG_WIPES_OKAY */
  180.